//专门处理用户的业务逻辑
//1. express框架
const express = require('express');
const fs = require('fs');
const path = require('path');
//2.创建一个后台路由
const router = express.Router();
// 导入用户数据模块
const hotModel = require('../../model/hotModel')
// 导入生成id的包
const {
    v4: uuidv4
} = require('uuid');

//导入获取当前时间的包
const moment = require('moment')

//接口4 查询数据
router.post('/hotlist', async (req, res) => {
    //接收前端提交的参数
    await hotModel.hotList().then(
            content => {
                res.send(content)
            }
        )
        .catch(
            error => {
                res.send(error)
            })
})
router.post('/alllist', async (req, res) => {
    //接收前端提交的参数
    await hotModel.allList().then(
            content => {
                res.send(content)
            }
        )
        .catch(
            error => {
                res.send(error)
            })
})
router.post('/toplist', async (req, res) => {
    //接收前端提交的参数
    await hotModel.topList().then(
            content => {
                res.send(content)
            }
        )
        .catch(
            error => {
                res.send(error)
            })
})
router.post('/drinklist', async (req, res) => {
    //接收前端提交的参数
    await hotModel.drinkList().then(
            content => {
                res.send(content)
            }
        )
        .catch(
            error => {
                res.send(error)
            })
})
router.post('/goodslist', async (req, res) => {
    //接收前端提交的参数
    await hotModel.goodsList().then(
            content => {
                res.send(content)
            }
        )
        .catch(
            error => {
                res.send(error)
            })
})
router.post('/shoplist', async (req, res) => {
    //接收前端提交的参数
    await hotModel.shopList().then(
            content => {
                res.send(content)
            }
        )
        .catch(
            error => {
                res.send(error)
            })
})
router.post('/foodlist', async (req, res) => {
    //接收前端提交的参数
    await hotModel.foodList().then(
            content => {
                res.send(content)
            }
        )
        .catch(
            error => {
                res.send(error)
            })
})
router.post('/contentlist', async (req, res) => {
    //接收前端提交的参数
    let content_id = req.body.con_id;
    await hotModel.ContentList(content_id).then(
            content => {
                res.send(content)
            }
        )
        .catch(
            error => {
                res.send(error)
            })
})

//接口5 修改总计
router.post('/modifylist', async (req, res) => {
    //接收前端提交的参数
    let con_id = req.body.con_id;
    let con_total = req.body.con_total;
    await hotModel.modify(con_id, con_total).then(
            content => {
                res.send(content)
            }
        )
        .catch(
            error => {
                res.send(error)
            })
})

//接口6 增加购物车列表的数据
router.post('/addlist', async (req, res) => {
    //接收前端提交的参数
    let car_id = req.body.car_id;
    let car_name = req.body.car_name;
    let car_img = req.body.car_img;
    let car_cup = req.body.car_cup;
    let car_temp = req.body.car_temp;
    let car_sugar = req.body.car_sugar;
    let car_total = req.body.car_total;
    await hotModel.add(car_id, car_name, car_img, car_cup, car_temp, car_sugar, car_total).then(
            content => {
                res.send(content)
            }
        )
        .catch(
            error => {
                res.send(error)
            })
})

//接口7 获取购物车全部数据
router.post('/carlist', async (req, res) => {
    //接收前端提交的参数
    await hotModel.carList().then(
            content => {
                res.send(content)
            }
        )
        .catch(
            error => {
                res.send(error)
            })
})

//接口8 删除购物车列表数据
router.post('/removelist', async (req, res) => {
    //接收前端提交的参数
    let car_id = req.body.car_id;

    await hotModel.remove(car_id).then(
            content => {
                res.send(content)
            }
        )
        .catch(
            error => {
                res.send(error)
            })
})

//接口9  搜索内容数据
router.post('/searchlist', async (req, res) => {
    //接收前端提交的参数
    let con_name = req.body.con_name;

    await hotModel.countList(con_name).then(
            content => {
                res.send(content)
            }
        )
        .catch(
            error => {
                res.send(error)
            })
})

//接口10 添加订单数据
router.post('/addorder', async (req, res) => {
    //接收前端提交的参数
    let ord_id = req.body.ord_id;
    let ord_name = req.body.ord_name;
    let ord_address = req.body.ord_address;
    let ord_count = req.body.ord_count;
    let ord_total = req.body.ord_total;
    let ord_time = moment().format('YYYY-MM-DD HH:mm:ss');

    await hotModel.addOrder(ord_id, ord_name, ord_address, ord_count, ord_total, ord_time).then(
            content => {
                res.send(content)
            }
        )
        .catch(
            error => {
                res.send(error)
            })
})

//接口11 查询订单数据
router.post('/orderlist', async (req, res) => {
    //接收前端提交的参数
    await hotModel.orderList().then(
            content => {
                res.send(content)
            }
        )
        .catch(
            error => {
                res.send(error)
            })
})

//接口12 删除订单数据
router.post('/removeorder', async (req, res) => {
    //接收前端提交的参数
    let ord_id = req.body.ord_id;

    await hotModel.removeOrder(ord_id).then(
            content => {
                res.send(content)
            }
        )
        .catch(
            error => {
                res.send(error)
            })
})

//接口13 删除购物车全部数据 
router.post('/removecar', async (req, res) => {
    //接收前端提交的参数
    await hotModel.removeCar().then(
            content => {
                res.send(content)
            }
        )
        .catch(
            error => {
                res.send(error)
            })
})

//接口14 添加已完成订单数据
router.post('/addfinish', async (req, res) => {
    //接收前端提交的参数
    let finish_id = req.body.finish_id;
    let finish_name = req.body.finish_name;
    let finish_address = req.body.finish_address;
    let finish_count = req.body.finish_count;
    let finish_total = req.body.finish_total;
    let finish_time = moment().format('YYYY-MM-DD HH:mm:ss');

    await hotModel.addFish(finish_id, finish_name, finish_address, finish_count, finish_total, finish_time).then(
            content => {
                res.send(content)
            }
        )
        .catch(
            error => {
                res.send(error)
            })
})

//接口15 查询已完成订单数据
router.post('/finishlist', async (req, res) => {
    //接收前端提交的参数
    await hotModel.finishList().then(
            content => {
                res.send(content)
            }
        )
        .catch(
            error => {
                res.send(error)
            })
})

//接口16 添加未完成订单数据
router.post('/addundone', async (req, res) => {
    //接收前端提交的参数
    let undone_id = req.body.undone_id;
    let undone_name = req.body.undone_name;
    let undone_address = req.body.undone_address;
    let undone_count = req.body.undone_count;
    let undone_total = req.body.undone_total;
    let undone_time = moment().format('YYYY-MM-DD HH:mm:ss');

    await hotModel.addUndone(undone_id, undone_name, undone_address, undone_count, undone_total, undone_time).then(
            content => {
                res.send(content)
            }
        )
        .catch(
            error => {
                res.send(error)
            })
})

//接口17 查询未完成订单数据
router.post('/undonelist', async (req, res) => {
    //接收前端提交的参数
    await hotModel.undoneList().then(
            content => {
                res.send(content)
            }
        )
        .catch(
            error => {
                res.send(error)
            })
})

//接口18 添加地址
router.post('/address', async (req, res) => {
    //接收前端提交的参数
    let address_name = req.body.address_name;
    await hotModel.address(address_name).then(
            content => {
                res.send(content)
            }
        )
        .catch(
            error => {
                res.send(error)
            })
})

//接口19 查询地址
router.post('/addresslist', async (req, res) => {
    //接收前端提交的参数
    await hotModel.addressList().then(
            content => {
                res.send(content)
            }
        )
        .catch(
            error => {
                res.send(error)
            })
})

//接口20 删除未完成订单
router.post('/removeundone', async (req, res) => {
    //接收前端提交的参数
    let undone_id = req.body.undone_id;

    await hotModel.removeUndone(undone_id).then(
            content => {
                res.send(content)
            }
        )
        .catch(
            error => {
                res.send(error)
            })
})

//接口21 添加收藏
router.post('/addcollect', async (req, res) => {
    //接收前端提交的参数
    let collect_id = req.body.collect_id;
    let collect_name = req.body.collect_name;
    let collect_img = req.body.collect_img;
    let collect_text = req.body.collect_text;
    let collect_price = req.body.collect_price;

    await hotModel.addCollect(collect_id, collect_name, collect_img, collect_text, collect_price).then(
            content => {
                res.send(content)
            }
        )
        .catch(
            error => {
                res.send(error)
            })
})

//接口22 查询收藏
router.post('/collectlist', async (req, res) => {
    //接收前端提交的参数
    await hotModel.collectList().then(
            content => {
                res.send(content)
            }
        )
        .catch(
            error => {
                res.send(error)
            })
})

//接口23 删除收藏
router.post('/removecollect', async (req, res) => {
    //接收前端提交的参数
    let collect_id = req.body.collect_id;

    await hotModel.removeCollect(collect_id).then(
            content => {
                res.send(content)
            }
        )
        .catch(
            error => {
                res.send(error)
            })
})

//接口24 修改杯型
router.post('/modifycup', async (req, res) => {
    //接收前端提交的参数
    let con_id = req.body.con_id;
    let con_cup = req.body.con_cup;

    await hotModel.modifyCup(con_id, con_cup).then(
            content => {
                res.send(content)
            }
        )
        .catch(
            error => {
                res.send(error)
            })
})

//接口25 修改温度
router.post('/modifytemp', async (req, res) => {
    //接收前端提交的参数
    let con_id = req.body.con_id;
    let con_temp = req.body.con_temp;

    await hotModel.modifyTemp(con_id, con_temp).then(
            content => {
                res.send(content)
            }
        )
        .catch(
            error => {
                res.send(error)
            })
})

//接口26 修改糖度
router.post('/modifysugar', async (req, res) => {
    //接收前端提交的参数
    let con_id = req.body.con_id;
    let con_sugar = req.body.con_sugar;

    await hotModel.modifySugar(con_id, con_sugar).then(
            content => {
                res.send(content)
            }
        )
        .catch(
            error => {
                res.send(error)
            })
})


//4.把当前路由暴露在模块系统下
module.exports = router;